﻿using System.Windows;
using System.Windows.Data;
using System;
namespace DeepEarth.Map.Core.Converters
{
    public class PointToPositionOriginConverter : IValueConverter
    {
        public static Point ConvertBack(PositionOrigin po)
        {
            return new Point { X = po.X, Y = po.Y };
        }

        public static PositionOrigin Convert(Point p)
        {
            return new PositionOrigin { X = p.X, Y = p.Y };
        }

        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(PositionOrigin))
                return Convert((Point)value);

            if (targetType == typeof(Point))
                return ConvertBack(value, targetType, true, culture);

            throw new ArgumentException("PointToPositionOriginConverter can only convert between Point and PositionOrigin");

        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ConvertBack((PositionOrigin)value);
        }

    }
}
